# set compile flags for MSVC

set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W4 /EHsc /GR")
set(CMAKE_C_FLAGS ${CMAKE_CXX_FLAGS})

if(SOFTART_PLATFORM_BITNESS EQUAL 32)
	set(CMAKE_CXX_FLAGS_DEBUG "/ZI")
	set(CMAKE_CXX_FLAGS_RELEASE "/arch:SSE")
	set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/arch:SSE")
	set(CMAKE_CXX_FLAGS_MINSIZEREL "/arch:SSE")
else()
	set(CMAKE_CXX_FLAGS_DEBUG "/Zi")
	set(CMAKE_CXX_FLAGS_RELEASE "")
	set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "")
	set(CMAKE_CXX_FLAGS_MINSIZEREL "")
endif()

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /Ob0 /RTC1 /MDd /GS /fp:precise /D_DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ob2 /GS- /fp:fast /MD /DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 /Ob2 /GS- /fp:fast /MD /DNDEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /O1 /Ob1 /GS- /fp:fast /MD /DNDEBUG")

if(MSVC_VERSION GREATER 1500)
	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP")
	set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MP")
	set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MP")
endif()
if(MSVC_VERSION GREATER 1400)
	if(SOFTART_PLATFORM_BITNESS EQUAL 32)
		set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /analyze")
		set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /analyze")
		set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /analyze")
		set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /analyze")
	endif()
endif()
if(MSVC_VERSION GREATER 1300)
	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
	set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL")
	set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /GL")
endif()

set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
set(CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})

foreach(flag_var
	CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
	set(${flag_var} "")
endforeach(flag_var)
foreach(flag_var
	CMAKE_EXE_LINKER_FLAGS_DEBUG CMAKE_MODULE_LINKER_FLAGS_DEBUG CMAKE_SHARED_LINKER_FLAGS_DEBUG)
	set(${flag_var} "/INCREMENTAL /DEBUG")
endforeach(flag_var)
foreach(flag_var
	CMAKE_EXE_LINKER_FLAGS_RELEASE CMAKE_MODULE_LINKER_FLAGS_RELEASE CMAKE_SHARED_LINKER_FLAGS_RELEASE)
	set(${flag_var} "/INCREMENTAL:NO /OPT:REF /OPT:ICF")
endforeach(flag_var)
foreach(flag_var
	CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO)
	set(${flag_var} "/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF")
endforeach(flag_var)
foreach(flag_var
	CMAKE_EXE_LINKER_FLAGS_MINSIZEREL CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL)
	set(${flag_var} "/INCREMENTAL:NO /OPT:REF /OPT:ICF")
endforeach(flag_var)

if(MSVC_VERSION GREATER 1300)
	foreach(flag_var
		CMAKE_EXE_LINKER_FLAGS_RELEASE CMAKE_MODULE_LINKER_FLAGS_RELEASE CMAKE_SHARED_LINKER_FLAGS_RELEASE)
		set(${flag_var} "${${flag_var}} /LTCG")
	endforeach(flag_var)
	foreach(flag_var
		CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO)
		set(${flag_var} "${${flag_var}} /LTCG")
	endforeach(flag_var)
	foreach(flag_var
		CMAKE_EXE_LINKER_FLAGS_MINSIZEREL CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL)
		set(${flag_var} "${${flag_var}} /LTCG")
	endforeach(flag_var)
endif()